<?php
require_once("include/conexion.php");
$token = "ccf4ea1073d17b7640fc146a324d8b2a";
if(isset($_POST["token"]) && $token==$_POST["token"]){
	$con = new Conexion();
	if($con->getStatus()=="0x0"){
		$idMovie = $con->setMovie($_POST["title"],$_POST["originalTitle"],$_POST["duration"],$_POST['releaseDate'],$_POST["idMpaa"],$_POST["imdbRating"],$_POST["imdbCode"],$_POST["youtubeCode"],$_POST["image"],$_POST["sinopsis"]);
		if(is_numeric($idMovie)){
			if(count($_POST["videoQuality"])>0) $con->setVideoMovie($idMovie, $_POST["videoQuality"]);
			if(count($_POST["audioLanguage"])>0) $con->setAudioMovie($idMovie, $_POST["audioLanguage"]);
			if(count($_POST["genre"])>0) $con->setGenreMovie($idMovie, $_POST["genre"]);
			$response["code"] = "0x0";
			$response["gls"] = "Almacenamiento exitoso";
		}else{
			$response["code"] = "E0x4";
			$response["gls"] = "Error al guardar en la base de datos";
		}
	}else{
		$response["code"] = "E0x3";
		$response["gls"] = "Error al conectar a la base de datos";
	}
}else{
	$response["code"] = "E0x2";
	$response["gls"] = "Token invalido o no existe ".$_POST["title"]."<-";
}
if(isset($_GET['callback'])){ // Si es una petición cross-domain
    echo $_GET['callback'].'('.json_encode($response).')';
}else{
	echo json_encode($response);
}
?>